package LeetCode;

import javax.print.attribute.standard.NumberUp;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}16:13
 */
public class interview57II {
//    public int singleNumber(int[] nums){
//        int result = 0;
//        for (int i = 0; i < 32; i++){
//            int count = 0;
//            int index = 1 << i;
//            for (int j : nums){
//                if ((index&j)!=0){
//                    count++;
//                }
//            }
//            if (count%3==1){
//                result|=index;
//            }
//        }
//        return result;
//    }
    public static void main(String[] args) {
        int[] arr = {3,3,4,3};
        System.out.println(new interview57II().singleNumber(arr));
    }

    public int singleNumber(int[] nums){
        if (nums == null){
            return 0;
        }
        int[] bitSet = new int[32];
        for (int i = 0; i < nums.length; i++){
            int index = 1;
            for (int j = 31; j >= 0; j--){
                int re = nums[i] & index;
                if (re!=0){//说明中标
                    bitSet[j] += 1;
                }
                index <<= 1;
            }
        }

        int result = 0;
        for (int i = 0; i < 32; i++){
            result <<= 1;
            result += bitSet[i]%3;

        }
        return result;
    }
}
